package 题目集.倍增算法.st表;

import org.junit.Test;

public class ch00_小于等于x的最大二次幂 {

    public static int ans(int x) {
        return (int) (Math.log(x) / Math.log(2));
    }

    public static int fun(int x) {
        int ans=0;
        x >>= 1;    //预先将x右移一位，防止溢出
        while (1<<ans <= x) {   //越过x/2时退出
            ans++;
        }
        return ans;
    }

    @Test
    public void test(){
        int n = 10;
        System.out.println(fun(n));
        System.out.println(ans(n));
        n=2000000000;
        System.out.println(fun(n));
        System.out.println(ans(n));
    }
}
